//
//  SettingInterfaceViewController.m
//  ProjectA
//
//  Created by 李赐岩 姜雪 张昕锐 on 15/3/5.
//  Copyright (c) 2015年 李赐岩 姜雪 张昕锐. All rights reserved.
//

#import "SettingInterfaceViewController.h"

@interface SettingInterfaceViewController ()

@end

@implementation SettingInterfaceViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithWhite:240 / 255.0 alpha:1];
    self.navigationItem.title = @"我  的";
    
    
//背景图片
    self.backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user-background.jpg"]];
    self.backgroundImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height * 0.43);
    [self.view addSubview:self.backgroundImageView];
    
    
    
//用户头像
    self.userImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"userHead.png"]];
    self.userImageView.frame = CGRectMake(0, 0, self.view.frame.size.width * 0.26 ,  self.view.frame.size.width * 0.26);
    self.userImageView.center = CGPointMake(self.view.center.x, self.view.center.y * 0.48);
    UIGestureRecognizer *gesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    self.userImageView.userInteractionEnabled = YES;  //开启交互
    [self.userImageView addGestureRecognizer:gesture1];
    [self.view addSubview:self.userImageView];
    
        self.loginButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.loginButton.frame = CGRectMake(0, self.userImageView.frame.size.height + self.userImageView.frame.origin.y + 10, self.view.frame.size.width, 50);
        [self.loginButton setTitle:@"点击添加自己喜爱的头像" forState:(UIControlStateNormal)];
        [self.loginButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    
        [self.view addSubview:self.loginButton];

    
    
    
//TABLEVIEW
    UITableView *tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height * 0.48, self.view.frame.size.width, 150) style:(UITableViewStylePlain)];
    
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.scrollEnabled = NO;
    [self.view addSubview:tableview];
  
} //DID LOAD

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}//section number


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}//height


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
    
} //row number


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identify = @"reuse";
    
    UserPageCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    
    if ( cell == nil) {
        cell = [[UserPageCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identify    ];
        
    }
    
    if (0 == indexPath.row) {
        cell.imageview.image = [UIImage imageNamed:@"Favorites.png"];
        cell.titleLabel.text = @"我的收藏";
        
    }else if (1 == indexPath.row){
        
        cell.imageview.image = [UIImage imageNamed:@"ClearCache.png"];
        cell.titleLabel.text = @"清除缓存";
        
    }else if (2 == indexPath.row){
        
        cell.imageview.image = [UIImage imageNamed:@"aboutUs.png"];
        cell.titleLabel.text = @"关于我们";
    }
    
    
    return  cell;
    
} //cell

-(void)tapAction:(UITapGestureRecognizer *)sender
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    
    [self presentViewController:imagePicker animated:YES completion:^{
        
        
    }];
    
    
    
}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.userImageView.image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
    
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        MineResaveViewController *mineResave = [[MineResaveViewController alloc]init];
        [self.navigationController pushViewController:mineResave animated:YES];
        
        
    }//if
    
    if (1 == indexPath.row) {
        
        float cache = [[SDImageCache sharedImageCache] getSize] / 1024 / 1024; //缓存大小
        
        NSString *string = [NSString stringWithFormat:@"已成功清理缓存 %.2f M ", cache];   //提示信息内容
        
        UIAlertView *cacheAlert = [[UIAlertView alloc] initWithTitle:@"提  示" message:string delegate:self cancelButtonTitle:@"朕知道了" otherButtonTitles: nil];   //弹窗提示
        
        [cacheAlert show];

        [[SDImageCache sharedImageCache] clearDisk];   //清除缓存  上线之前暂时不执行
        
        
        
    }//if  清除缓存
    
    if (indexPath.row == 2) {
        
        //第三方弹框
        URBAlertView *alertView = [URBAlertView dialogWithTitle:@"开发者" subtitle:@"李赐岩 张昕锐 姜雪\n\n 电子邮箱1512989760@qq.com\n"];
        alertView.blurBackground = NO;
        [alertView addButtonWithTitle:@"Close"];
        [alertView setHandlerBlock:^(NSInteger buttonIndex, URBAlertView *alertView) {
            [self.alertView hideWithCompletionBlock:^{
               
            }];
        }];
        self.alertView = alertView;
    [self.alertView showWithAnimation:URBAlertAnimationTumble];
    
    }//if

} //选中方法




@end













